local skel = fk.CreateSkill {
  name = "efengqi__xiaoji",
}

Fk:loadTranslationTable{
  ["efengqi__xiaoji"] = "枭姬",
  [":efengqi__xiaoji"] = "当你失去：装备区中一张牌后，摸两张牌；至少两张牌后，你可以与一名其他角色各回复1点体力。",

  ["#efengqi__xiaoji-choose"] = "枭姬：你可选择一名其他角色，你与各回复1点体力",

  ["$efengqi__xiaoji1"] = "剑利弓急，你可打不过我的。",
  ["$efengqi__xiaoji2"] = "我会的武器，可多着呢。",
}

skel:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(skel.name) then return end
    local choices = {}
    local n = 0
    for _, move in ipairs(data) do
      if move.from == player then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerEquip then
            table.insert(choices, "draw")
          end
          if table.contains({Card.PlayerHand, Card.PlayerEquip}, info.fromArea) then
            n = n + 1
          end
        end
      end
    end
    if n > 1 then
      table.insert(choices, "recover")
    end
    if #choices > 0 then
      event:setCostData(self, {choices = choices})
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    local cost = event:getCostData(self)
    if table.contains(cost.choices, "recover") then
      local tos = player.room:askToChoosePlayers(player, {
        min_num = 1, max_num = 1, targets = player.room:getOtherPlayers(player, false), skill_name = skel.name,
        prompt = "#efengqi__xiaoji-choose",
      })
      if #tos > 0 then
        cost.tos = tos
        event:setCostData(self, cost)
      else
        table.removeOne(cost.choices, "recover")
        if #cost.choices == 0 then return false end
      end
    end
    return true
  end,
  on_use = function(self, event, target, player, data)
    local cost = event:getCostData(self)
    for _, ch in ipairs(cost.choices) do
      if player.dead then break end
      if ch == "draw" then
        player:drawCards(2, self.name)
      end
    end
    if cost.tos then
      local to = event:getCostData(self).tos[1]
      if player:isWounded() and player:isAlive() then
        player.room:recover{
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name
        }
      end
      if to:isWounded() and to:isAlive() then
        player.room:recover{
          who = to,
          num = 1,
          recoverBy = player,
          skillName = self.name
        }
      end
    end
  end,
})



return skel
